//页面加载完后响应onReady事件
$(function(){	
	spreadSpeedInfo();
	getAllCheckPointConfig();
});	



function getAllCheckPointConfig(){
	$.ajax({
		url:ctx+'/urgentrptmgr/speedReportAction!getRuleByReportId.action',
		data:{reportId:$('#reportid').val(),reportType:$("#reporttype").val()},
		dataType:'json',
		success:function(data){						
			createGZInfo(data);//构造时间轴				
		}
	});
}

//收缩按钮事件
function spreadSpeedInfo()
{
	$("#addDiv").slideUp("slow"); //关闭添加急报快报文本框
	$("#speedreportInfoDiv").slideDown("slow"); //展开急报快报信息
	$("#showGZDiv").css("height", "480px");
}

//展开按钮事件
function spreadSpeedReportInfo()
{
	$("#addDiv").slideDown("slow"); //关闭添加急报快报文本框
	$("#speedreportInfoDiv").slideUp("slow"); 
	$("#showGZDiv").css("height", "303px");
}

//st:对象  type:class名称  change:改变小图标的名称
function cbart (st,type,change) 
{ 
	document.getElementById(st).className = type;
	if(change!=""&&change!=null&&change!=undefined)
	{
		$("#"+st).children().children().attr("src",ctx+"/images/speedreport/"+change);
	}
} 
function sbart (st,type,change)
{ 
	document.getElementById(st).className = type;
	if(change!=""&&change!=null&&change!=undefined)
	{
		$("#"+st).children().children().attr("src",ctx+"/images/speedreport/"+change);
	}
}

//规则信息
function createGZInfo(data)
{
	var innerHTML="";
	//时间轴
	var dataHTML = "";
	//展示数据
	var lrzjHTML = "";
	if (data != null && data != "")
	{
		for (var i=0;i<data.length;i++)
		{
			dataHTML += '<li><a href="#nogo"></a></li>';
			if(i%2==0)
			{
				lrzjHTML+='<li>';
				lrzjHTML+='	<table style="background: url('+ctx+'/js/timeline/images/up_content.png);width:300px;height:168px;" border="0">';
				lrzjHTML+='		<tr style="height: 45px;">';
				lrzjHTML+='			<td align="left"><div class="showGZ-text1" style="color: #4f8fc7;font-size: 14px;" title="'+data[i].chekcRuleName+'">'+data[i].chekcRuleName+'</div></td>';
				lrzjHTML+='			<td align="right"></td>';
				lrzjHTML+='		</tr>';
				lrzjHTML+='	<tr style="height: 28px;">';
				lrzjHTML+='<td align="left" style="padding-left: 5px;">规则算法：'+data[i].ruleAlgorithmName+'</td>';
				lrzjHTML+='<td align="left">告警级别：';
				lrzjHTML +='<em class="'+warnLevelColor(data[i].warnLevel)+'" >'+data[i].warnLevelName+'</em>';
				lrzjHTML +='</td>';
				lrzjHTML+='	</tr>';
				lrzjHTML+='	<tr style="height: 28px;">';
				lrzjHTML+='	<td colspan="2" align="left" style="padding-left: 5px;">阀值上限：'+data[i].thresholdMax+'</td>';
				lrzjHTML+='	</tr>';
				lrzjHTML +='<tr style="height: 28px;">';
				lrzjHTML +='<td colspan="2" align="left" style="padding-left: 5px;">阀值下限：'+data[i].thresholdMin;
				lrzjHTML +='</td>';
				lrzjHTML +='</tr>';
				lrzjHTML +='<tr>';
				lrzjHTML +='<td colspan="2"></td>';
				lrzjHTML +='</tr>';
				lrzjHTML+='	</table>';
				lrzjHTML+='	<div style="position:relative;top:38px;left:88px; float:left">';
				lrzjHTML+='	<table style="height:41px" cellpadding="0" cellspacing="0">';
				lrzjHTML+='		<tr>';
				lrzjHTML+='			<td  style="background: url('+ctx+'/js/timeline/images/up_left.png);width:10px"></td>';
				lrzjHTML+='			<td  style="background: url('+ctx+'/js/timeline/images/up_center.png); vertical-align:middle">';
				lrzjHTML+=data[i].dataLevelName+'</td>';
				lrzjHTML+='			<td  style="background: url('+ctx+'/js/timeline/images/up_right.png);width:38px"></td>';
				lrzjHTML+='	</tr>';
				lrzjHTML+='	</table>';
				lrzjHTML+='</div>';
				lrzjHTML+='</li>';
			}
			else
			{
				lrzjHTML+='<li style="position:relative;z-index:999999;top:-7px;">';
				lrzjHTML+='	<table style="background: url('+ctx+'/js/timeline/images/down_content.png);width:300px;height:168px;" border="0">';
				lrzjHTML +='<tr>';
				lrzjHTML +='<td colspan="2"></td>';
				lrzjHTML +='</tr>';
				lrzjHTML+='		<tr style="height: 45px;">';
				lrzjHTML+='			<td align="left"><div class="showGZ-text1" style="color: #4f8fc7;font-size: 14px;" title="'+data[i].chekcRuleName+'">'+data[i].chekcRuleName+'</div></td>';
				lrzjHTML+='			<td align="right"></td>';
				lrzjHTML+='		</tr>';
				lrzjHTML+='	<tr style="height: 28px;">';
				lrzjHTML+='<td align="left" style="padding-left: 5px;">规则算法：'+data[i].ruleAlgorithmName+'</td>';
				lrzjHTML+='<td align="left">告警级别：';
				lrzjHTML +='<em class="'+warnLevelColor(data[i].warnLevel)+'" >'+data[i].warnLevelName+'</em>';
				lrzjHTML +='</td>';
				lrzjHTML+='	</tr>';
				lrzjHTML+='	<tr style="height: 28px;">';
				lrzjHTML+='	<td colspan="2" align="left" style="padding-left: 5px;">阀值上限：'+data[i].thresholdMax+'</td>';
				lrzjHTML+='	</tr>';
				lrzjHTML +='<tr style="height: 28px;">';
				lrzjHTML +='<td colspan="2" align="left" style="padding-left: 5px;">阀值下限：'+data[i].thresholdMin;
				lrzjHTML +='</td>';
				lrzjHTML +='</tr>';
				lrzjHTML+='	</table>';
				lrzjHTML+='	<div style="position:relative;top:-243px;left:102px; float:left">';
				lrzjHTML+='	<table style="height:41px" cellpadding="0" cellspacing="0">';
				lrzjHTML+='		<tr>';
				lrzjHTML+='			<td  style="background: url('+ctx+'/js/timeline/images/down_left.png);width:10px"></td>';
				lrzjHTML+='			<td  style="background: url('+ctx+'/js/timeline/images/down_center.png);vertical-align:middle">';
				lrzjHTML+=data[i].dataLevelName+'</td>';
				lrzjHTML+='			<td  style="background: url('+ctx+'/js/timeline/images/down_right.png);width:38px"></td>';
				lrzjHTML+='		</tr>';
				lrzjHTML+='	</table>';
				lrzjHTML+='</div>';
				lrzjHTML+='</li>';
			}
		}
		
		innerHTML+='<div id="lrzj_x">';
		innerHTML+='<ul id="dates">';
		innerHTML+=dataHTML;
		innerHTML+='</ul>';
		innerHTML+='<ul id="lrzj_line">';
		innerHTML+=lrzjHTML;
		innerHTML+='</ul>';
		innerHTML+='<a href="#" id="next">+</a>';
		innerHTML+='<a href="#" id="prev">-</a>';
		innerHTML+='</div>';
		$("#showGZDiv").html(innerHTML);
		$().timelinr();
		
	}
	else
	{
		$("#showGZDiv").html(innerHTML);
	}
}

/**
 * 根据告警级别，告警内容显示相应的颜色
 * @param warnLevel
 */
function warnLevelColor(warnLevel)
{
	var className = "";
	
	//严重告警
	if (warnLevel == 3)
	{
		className = "warn_serious";
	}
	
	//重要告警
	else if (warnLevel == 2)
	{
		className = "warn_important";
	}
	
	//一般告警
	else if (warnLevel == 1)
	{
		className = "warn_common";
	}
	
	//正常
	else
	{
		className = "warn_normal";
	}
	
	return className;
}
